/**
 * @Project TMHSCFX
 * @Author Tran Manh Hung
 * @Email: hungtmit@gmail.com | tmh@xwebgate.com
 * @Copyright © 2011 TMH. All rights reserved
 * @Createdate Apr 19, 2011
 * @Createtime 11:37:14 PM
 */

package com.tmh.study.fAS3AMTM.chap7
{
	import com.tmh.study.fAS3AMTM.chap5.Ball;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class MouseEvents extends Sprite
	{
		public function MouseEvents()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}

		private function addedToStageHandler(event:Event):void
		{
			initData();
		}

		private function initData():void
		{
			var ball:Ball = new Ball();
			ball.x = 100;
			ball.y = 100;
			addChild(ball);
			ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownBall);
			ball.addEventListener(MouseEvent.MOUSE_UP, onMouseUpBall);
			ball.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveBall);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownStage);
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpStage);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveStage);
		}

		private function onMouseDownBall(event:MouseEvent):void
		{
			trace("mouse down - ball");
		}

		private function onMouseUpBall(event:MouseEvent):void
		{
			trace("mouse up - ball");
		}

		private function onMouseMoveBall(event:MouseEvent):void
		{
			trace("mouse move - ball");
		}

		private function onMouseDownStage(event:MouseEvent):void
		{
			trace("mouse down - stage");
		}

		private function onMouseUpStage(event:MouseEvent):void
		{
			trace("mouse up - stage");
		}

		private function onMouseMoveStage(event:MouseEvent):void
		{
			trace("mouse move - stage");
		}
	}
}